import request from '@/utils/request'

export function getProductList(params: ProductListParamsType) {
  return request<ProductListType>({
    url: '/product/product',
    method: 'get',
    params,
  })
}

export function setProductStatus(id: number, status: number) {
  return request({
    url: `/product/product/set_show/${id}/${status}`,
    method: 'put',
  })
}

export function getProductInfo(id: number) {
  return request<ProductDetailsType>({
    url: `/product/product/${id}`,
    method: 'get',
  })
}

export function submitProduct(id: number, data: ProductFormType) {
  return request({
    url: `/product/product/${id}`,
    method: 'post',
    data,
  })
}

// 批量上架
export function putProductOnBatch(data: { ids: number[] }) {
  return request({
    url: `/product/product/product_show`,
    method: 'put',
    data,
  })
}

// 批量下架
export function putProductOffBatch(data: { ids: number[] }) {
  return request({
    url: `/product/product/product_unshow`,
    method: 'put',
    data,
  })
}

export function getStatusList() {
  return request<{ list: ProductStatusType[] }>({
    url: `/product/product/type_header`,
    method: 'get',
  })
}

export function getProductAttrList(params: {
  page?: number
  limit?: number
  rule_name?: string
}) {
  return request<ProductAttrListType>({
    url: `/product/product/rule`,
    method: 'get',
    params,
  })
}

export function genProductMultiAttr(
  id: number,
  type: number,
  data: { attrs: MultiAttrListType[] }
) {
  return request<MultiAttrTabelType>({
    url: `/product/generate_attr/${id}/${type}`,
    method: 'post',
    data,
  })
}

export function delProduct(id: number) {
  return request({
    url: `/product/product/${id}`,
    method: 'delete',
  })
}

export function submitProductAttr(data: ProductAttrInfoType, id: number = 0) {
  return request({
    url: `/product/product/rule/${id}`,
    method: 'post',
    data,
  })
}

export function getProductAttrInfo(id: number) {
  return request<{ info: ProductAttrInfoType }>({
    url: `/product/product/rule/${id}`,
    method: 'get',
  })
}

export function delProductAttr(data: { ids: string }) {
  return request({
    url: `/product/product/rule/delete`,
    method: 'delete',
    data,
  })
}

export function getProductCommentList(params: {
  is_reply: string
  data: string
  store_name: string
  account: string
  product_id: string
  page: number
  limit: number
}) {
  return request<ProductCommentListType>({
    url: `/product/reply`,
    method: 'get',
    params,
  })
}

export function submitComment(data: any) {
  return request({
    url: `/product/reply/save_fictitious_reply.html`,
    method: 'post',
    data,
  })
}

export function delComment(id: number) {
  return request({
    url: `/product/reply/${id}`,
    method: 'delete',
  })
}

export function replyComment(id: string, data: { content: string }) {
  return request({
    url: `/product/reply/set_reply/${id}`,
    method: 'put',
    data,
  })
}
